package com.teradata.bigdata.iop.security;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.*;
import java.io.IOException;

/**
 * @Project:
 * @Description:  开启jwt验证
 * @Version 1.0.0
 * @Throws SystemException:
 * @Author: <li>2019/1/15/015 Administrator Create 1.0
 * @Copyright ©2018-2019 al.github
 * @Modified By:
 */
@Configuration
public class BeanRegisterConfig {

    @Value("${server.security}")
    private boolean isSecurity;

    @Bean
    public FilterRegistrationBean createFilterBean() {
        //过滤器注册类
        FilterRegistrationBean registration = new FilterRegistrationBean();
        if (isSecurity){
            registration.setFilter(new JwtFilter());
            //需要过滤的接口
            registration.addUrlPatterns("/iop/*");
        }else{
            registration.setFilter((servletRequest, servletResponse, filterChain) -> {

            });
            registration.addUrlPatterns("/datax/*");
        }
        return registration;
    }
}
